package cn.tedu.knows.portal;

import cn.tedu.knows.portal.mapper.ClassroomMapper;
import cn.tedu.knows.portal.mapper.TagMapper;

import cn.tedu.knows.portal.mapper.UserMapper;
import cn.tedu.knows.portal.model.Classroom;
import cn.tedu.knows.portal.model.Permission;
import cn.tedu.knows.portal.model.Tag;
import cn.tedu.knows.portal.model.User;
import cn.tedu.knows.portal.service.IUserService;
import cn.tedu.knows.portal.vo.RegisterVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class Tagtest {
    @Autowired
    TagMapper tagMapper;
    @Test
    public void getAll(){
        List<Tag> tags=tagMapper.selectList(null);
        for (Tag t:tags) {
            System.out.println(t);
        }
    }
    @Autowired
    UserMapper userMapper;
    @Test
    public void userMapperTest(){
        User user=userMapper.findUserByUsername("st2");
        List<Permission> list=userMapper.findUserPermissionsById(user.getId());
        System.out.println(user);
        for (Permission p: list) {
            System.out.println(p);
        }
    }

    //MybatisPlus提供的条件查询
    @Autowired
    ClassroomMapper classroomMapper;
    @Test
    public void query(){
        //实例化QueryWrapper对象,泛型指定查询的表
        //这个对象本身就是一个条件的含义
        QueryWrapper<Classroom> query=new QueryWrapper<>();
        //设定查询条件,eq是相等的意思([列名],[值])
        query.eq("invite_code","JSD2003-005803");
        Classroom classroom=classroomMapper.selectOne(query);
        System.out.println(classroom);
    }
    @Autowired
    IUserService userService;
    @Test
    public void abc(){
        RegisterVO registerVO=new RegisterVO();
        registerVO.setPhone("18556794023");
        registerVO.setNickname("吴狗");
        registerVO.setInviteCode("JSD2003-005803");
        registerVO.setPassword("123456");
        userService.registerStudent(registerVO);
        System.out.println("ok");
    }
}
